﻿using System;
using System.Collections.Generic;
using System.Web;
using hedefgrup.reports.renault.database;
using System.Data;

/// <summary>
/// Summary description for fiatUser
/// </summary>
public class fiat
{
    private const string SESSION_USER_KEY = "384BFF87-198F-48BF-BC62-C7E800D59BFE";

    public static bool loginUser(string username, string password)
    {
        DataTable dt = db.query("SELECT * FROM [fiatuser] WHERE [username] = @p_0 AND password = @p_1", username, password);
        if (dt.Rows.Count > 0)
        {
            HttpContext.Current.Session[SESSION_USER_KEY] = true;
            return true;
        }
        else
        {
            HttpContext.Current.Session[SESSION_USER_KEY] = false;
            return false;
        }
    }

    public static bool isUserLoggedIn()
    {
        if (HttpContext.Current == null) return false;
        if (HttpContext.Current.Session == null) return false;
        if (HttpContext.Current.Session[SESSION_USER_KEY] == null) return false;
        if (HttpContext.Current.Session[SESSION_USER_KEY].GetType() != typeof(bool)) return false;
        return (bool)HttpContext.Current.Session[SESSION_USER_KEY] == true;
    }


}
